/**
 * @Description: SQL帮助类
 * @Author: lxt
 * @CreateDate: 2019/11/1
 **/
public class SqlHelper {
    /***
     * 根据数据库、表信息生成统计语句
     * @param dataBaseType  数据库类型
     * @param catalog   数据库catalog
     * @param schema    数据库schema
     * @param tableName 表名
     * @return
     */
    public String getSql(String dataBaseType, String catalog, String schema, String tableName) {
        String sql = "";
        if ("mysql".equals(dataBaseType)) {
            sql = "SELECT TABLE_ROWS AS NUMBER FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '"
                    + catalog
                    + "' AND TABLE_NAME = '"
                    + tableName
                    + "'";
        } else if ("postgresql".equals(dataBaseType)) {
            sql = "SELECT RELTUPLES AS NUMBER FROM PG_CLASS WHERE RELKIND = 'R' AND RELNAME = '"
                    + tableName
                    + "' AND RELNAMESPACE = (SELECT OID FROM PG_NAMESPACE WHERE NSPNAME ='"
                    + schema
                    + "')";
        }
        return sql;
    }
}
